library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag(): dplyr, stats
library(janitor)
library(stringr)
library(forcats)
library(viridis)
## Loading required package: viridisLite
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
library(ggthemes)
ny_noaa_data_tidy = read_csv("./nynoaadat.zip") %>%
clean_names() %>%
drop_na() %>%
separate(date, into = c("year", "month", "day"), "-") %>%
mutate(month = as.factor(month), prcp = as.numeric(prcp), tmin = as.numeric(tmin),
prcp = prcp / 10,
tmin = tmin / 10) %>%
mutate(month = recode(month,
"01" = "January",
"02" = "February",
"03" = "March",
"04" = "April",
"05" = "May",
"06" = "June",
"07" = "July",
"08" = "August",
"09" = "September",
"10" = "October",
"11" = "November",
"12" = "December")) %>%
select (year, month, day, prcp, tmin, snow) %>%
filter(year <= "1989")
## Parsed with column specification:
## cols(
## id = col_character(),
## date = col_date(format = ""),
## prcp = col_integer(),
## snow = col_integer(),
## snwd = col_integer(),
## tmax = col_character(),
## tmin = col_character()
## )
Column
Monthly patterns of precipitation from 1981 to 1989
geom_path_ggplot =
ny_noaa_data_tidy %>%
group_by(month, year) %>%
summarize(average_prcp = mean(prcp, na.rm = TRUE)) %>%
ggplot(aes(x = month, y = average_prcp, group = year, color = year)) +
geom_path(alpha = 0.4)+
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x = "Month", y = "average precipitation (mm)")
ggplotly(geom_path_ggplot)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
Column
Range of minimun temperature in degrees C from 1981-1989
ny_noaa_data_tidy %>%
group_by(year) %>%
plot_ly(y = ~tmin, x = ~year, color = ~year, type = "box",
colors = "Set2")
Variation in precipitation depending on average minimun temperature
geom_smooth_ggplot =
ny_noaa_data_tidy %>%
ggplot(aes(x = tmin, y = prcp)) +
geom_smooth() +
labs( x = "tmin", y = "prcp")
ggplotly(geom_smooth_ggplot)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
## `geom_smooth()` using method = 'gam'